<?php
/**
 * Created on Jun 27, 2012
 * @author	HoangNV2
 * @desc	
 */
require_once SYS_APPS_INIT . 'AppHomeAction.class.php';
class loginAction extends AppHomeAction {
	function execute() {
		$username = $_POST['username'];
		$pass = $_POST['pw'];
		
		if ($username != '') {
			$conn=mysql_connect("localhost","root","12345678") or die("can't connect this database");
			mysql_select_db("demo",$conn);
			$sql="select * from user where username='".$username."' and password='".$pass."'";
	 		$query = mysql_query($sql);
	 		if(mysql_num_rows($query) == 0) {
	 			$this->tpl('login', 'home');
				//$msg = 'Moi Dang nhap';
				$this->assign('message', $sql);
				$this->assign('username', $username);
				$this->assign('action', '');
	 		} else {
	 			$row=mysql_fetch_array($query);
	 			print_r($row);
	 			$this->assign('username', $row['username'].'-'.$row['flag']);
				$this->tpl('login_succ', 'home');
	 		}
	 		
	 		
		} else {
			$this->assign('message', 'Dang nhap di');
			$this->assign('username', '');
			$this->assign('action', '');
		}
		
		return $this->output();
	}
}